package com.sxp.servlet;

import com.sxp.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author hsowan
 * @date 2019-06-13
 **/
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        if (user != null) {
            session.removeAttribute("user");
            session.setAttribute("msg", "退出成功！");
            resp.sendRedirect("/obs/message.jsp");
        } else {
            session.setAttribute("msg", "未登录！");
            resp.sendRedirect("/obs/message.jsp");
        }
    }
}
